package com.tarry.shop.search.service;

import com.tarry.shop.search.domain.dto.GoodsDTO;
import com.tarry.shop.search.repository.GoodsRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class GoodsSearchService {

//    @Autowired
//    private ElasticsearchRestTemplate elasticsearchRestTemplate;

    @Autowired
    private GoodsRepository goodsRepository;

    /**
     * 新增或者修改数据
     */
    public GoodsDTO save(GoodsDTO product) {
        return goodsRepository.save(product);
    }

    public List<SearchHit<GoodsDTO>> findAllByGoodsName(String goodsName) {
        List<SearchHit<GoodsDTO>> goodsList = goodsRepository.findGoodsDTOByGoodsName(goodsName);
        return goodsList;
    }

}
